from rest_framework import serializers
from approval.models import Approval, ApprovalUser, ApprovalType


# 首页展示
class ApprovalSer(serializers.ModelSerializer):

    # approval_type
    approval_type = serializers.SerializerMethodField(read_only=True)
    def get_approval_type(self,obj):
        return obj.approval_type.types

    # user
    user = serializers.SerializerMethodField(read_only=True)
    def get_user(self, obj):
        return obj.user.user_name

    # now_approval
    now_approval = serializers.SerializerMethodField(read_only=True)
    def get_now_approval(self, obj):
        return obj.now_approval.approval_user.user_name

    # department
    department = serializers.SerializerMethodField(read_only=True)
    def get_department(self, obj):
        return obj.department.department_name

    class Meta:
        model = Approval
        fields = '__all__'

